<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>上传图片验证</title>
    <script>
        window.onload = function(){
            var file = document.getElementById("file");
            file.onchange = function(){
                var path = this.value;
                //console.log(path);//C:\fakepath\bg.jpg
                var len = path.lastIndexOf(".");
                var str = path.substr(len);
                var str1 = str.toLowerCase();
                if(str1 === '.jpg' || str1 === '.png' || str1 === '.jpeg' || str1 === '.gif'){
                    alert("上传图片正确");
                }else{
                    alert("上传图片错误");
                }
            }
        }
    </script>
</head>
<body>
    <label for="file">上传图片验证:</label>
    <input type="file" name="" id="file">
</body>
</html>